package com.wlz.HDiffPatch;
import java.io.FileNotFoundException;



/**
 * 二进制文件差分Java版
 */
public class HdiffPatch {

    /**
     * 差分
     * @param oldFile 原始文件
     * @param newFile 目标文件
     * @param patchFile 差分文件
     * @throws FileNotFoundException oldFile或newFile不存在
     */
    public static void diff(String oldFile, String newFile, String patchFile) throws FileNotFoundException {
        FileUtils.requireFileExist(oldFile);
        FileUtils.requireFileExist(newFile);
        HDiff.INSTANCE.hdiffz(oldFile,newFile, patchFile, 1024*1024*128);
    }
    
    /**
     * 还原
     * @param oldFile 原始文件地址
     * @param diffPath 差分文件地址
     * @param outNewPath 还原新生成文件地址
     * @throws FileNotFoundException oldFile或patchFile不存在
     */
    public static void patch(String oldPath, String diffPath, String outNewPath) throws FileNotFoundException {
        FileUtils.requireFileExist(oldPath);
        FileUtils.requireFileExist(diffPath);
        HPatch.INSTANCE.hpatchz(oldPath, diffPath, outNewPath);
    }
    
    public static void main(String[] args) {
        System.out.println(System.getProperty("java.library.path"));
        String path = "/Users/wlz/Desktop/HDiffPatch/package2/";
        String oldFile = path + "B60V-TBXS012334.zip";
        String newFile = path + "B60V-TBXS012338.zip";
        String patchFile = path + "out_diff.zip";
        String outNewPath = path + "out_new.zip";
        try {
            HdiffPatch.diff(oldFile, newFile, patchFile);//差分
            HdiffPatch.patch(oldFile, patchFile, outNewPath);//还原
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println(patchFile);
    }
}